package com.atung.parking.controller;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/api/fegin")
@Api(tags = "车场三方调用")
public class DeviceController {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @RequestMapping("/enter/{parking}")
    @ApiOperation("三方进场")
    public JSONObject enterByCarNo(@PathVariable("parking") String parking, @RequestParam String carNo) {
        JSONObject result = new JSONObject();
        result.put("msg", "err");
        result.put("code", "1");
        result.put("open", "1");
        result.put("free", "0");
        if (stringRedisTemplate.opsForHash().hasKey(parking,
                carNo)) {
            String dateInfo = stringRedisTemplate.opsForHash().get(parking,
                    carNo).toString();

            Long currentTime =(System.currentTimeMillis());
            String[] split = dateInfo.split("-");
            long startTime = Long.parseLong(split[0]);
            long endTime = Long.parseLong(split[1]);
            if(startTime>currentTime&&currentTime<endTime){

            }

        }


        return result;
    }

    @RequestMapping("/exit/{parking}")
    @ApiOperation("（三方出场")
    public JSONObject exitByCarNoo(@PathVariable("parking") String parking, @RequestParam String carNo) {
        JSONObject result = new JSONObject();
        result.put("msg", "err");
        result.put("code", "1");
        result.put("open", "1");
        result.put("free", "0");
        if (stringRedisTemplate.opsForHash().hasKey(parking,
                carNo)) {
            String dateInfo = stringRedisTemplate.opsForHash().get(parking,
                    carNo).toString();

            Long currentTime =(System.currentTimeMillis());
            String[] split = dateInfo.split("-");
            long startTime = Long.parseLong(split[0]);
            long endTime = Long.parseLong(split[1]);
            if(startTime>currentTime&&currentTime<endTime){

            }

        }
        return result;
    }

}
